package com.tianqu.tms.www.proxymember.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.ProxyCarInfo;
import com.tianqu.tms.www.proxymember.controller.ProxyMemberCarListInputController;
import com.tianqu.tms.www.proxymember.viewhelper.ProxyMemberCarSearchInputViewHelper;

/**
 * @author zhangxueliang
 * 车辆搜索录入
 */
public class ProxyMemberCarListInputAction extends TmsAction{
	private Logger logger = Logger
	.getLogger(ProxyMemberCarListInputAction.class);
	public final static String PAGENO = "pageNo";
	public final static String SORTKEY = "sortKey";
	public final static String MAXINDEX = "maxIndex";
	public final static String ASC = "asc";
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		ProxyMemberCarSearchInputViewHelper viewhelp = new ProxyMemberCarSearchInputViewHelper();
		if(request.getParameter(PAGENO) == null) {
			uc.setAttribute(PAGENO, viewhelp.getPageNo());
			uc.setAttribute(SORTKEY, viewhelp.getSortKey());
			uc.setAttribute(MAXINDEX, viewhelp.getMaxIndex());
			uc.setAttribute(ASC, viewhelp.getAsc());
		} else {
			uc.setAttribute(PAGENO, request.getParameter(PAGENO));
			uc.setAttribute(SORTKEY, request.getParameter(SORTKEY));
			uc.setAttribute(MAXINDEX, request.getParameter(MAXINDEX));
			uc.setAttribute(ASC, request.getParameter(ASC));
		}
		ProxyMemberCarListInputController controller = new ProxyMemberCarListInputController();
		controller.execute(uc);
		viewhelp = (ProxyMemberCarSearchInputViewHelper)uc.getAttribute(TmsConstants.VIEWHELP);
		ProxyCarInfo proxyCarInfo = (ProxyCarInfo)uc.getAttribute(ProxyMemberCarListInputController.PAGING);
		viewhelp.setPageNo(Integer.toString(proxyCarInfo.getPageNo()));
		viewhelp.setMaxIndex(Integer.toString(proxyCarInfo.getMaxIndex()));
		viewhelp.setAsc(Boolean.toString(proxyCarInfo.isAsc()));
		viewhelp.setSortKey(Integer.toString(proxyCarInfo.getSortKey()));
		viewhelp.setTotalCount(Integer.toString(proxyCarInfo.getTotalCount()));
		viewhelp.setDateFrom(Integer.toString(proxyCarInfo.getDateFrom()));
		viewhelp.setDateTo(Integer.toString(proxyCarInfo.getDateTo()));
		
		
		request.setAttribute(VIEWHELP, viewhelp);
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
